home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / sample20.zip / RM.PAS < prev    next >
Pascal/Delphi Source File  |  1989-03-28  |  39KB  |  1,208 lines

  1.  
  2. {  Rowan McKenzie's personalised functions for Turbo Pascal 4  28/3/89}
  3.  
  4. Unit rm;
  5.  
  6.   {$v-}
  7.  
  8.   {************************************************************************}
  9.  
  10. Interface
  11.  
  12. Uses crt, graph, mousfunc, printer;
  13.  
  14.  
  15. Const
  16.   dialogstringlength = 100;
  17.   clickboxstringlength = 100;
  18.  
  19. Type
  20.   argtypes       = (_none, _boolean, _char, _integer, _real, _string);
  21.   dialogentryp   = ^dialogentrytype;
  22.   dialogentrytype = Record
  23.                       next           : dialogentryp;
  24.                       title          : String[dialogstringlength];
  25.                       Case argtype   : argtypes Of
  26.                         _none          : ();
  27.                         _boolean : (booleanresult : Boolean);
  28.                         _char : (charresult : Char);
  29.                         _integer : (integerresult : Integer);
  30.                         _real : (realresult     : Real;
  31.                                 decimalp       : Integer);
  32.                         _string : (stringresult   : String[dialogstringlength];
  33.                                   ssize : Byte; nulvalid : Boolean);
  34.                     End;
  35.   titletype      = (_text, _figure);
  36.   polypointp     = ^polypoint;
  37.   polypoint = Record
  38.                 x, y           : Integer;
  39.               End;
  40.   clickboxtypep  = ^clickboxtype;
  41.   clickboxtype = Record
  42.                    next           : clickboxtypep;
  43.                    x, y           : Integer; {box top left corner position}
  44.                    Case ttype     : titletype Of
  45.                      _text : (title : String[clickboxstringlength]);
  46.                      _figure : (numpoints : Word; polypoints : polypointp;
  47.                                 fill           : Boolean);
  48.                  End;
  49.  
  50. Var exitsave   : Pointer;
  51.   showerrormessage : Boolean;
  52.  
  53.  
  54. Procedure heaperrorinit;
  55.  
  56.   { initialised head error pointer to custom procedure}
  57.  
  58. Function log(a : Real)      : Real;
  59.  
  60.   { calculates log base 10 of a}
  61.  
  62. Procedure fixcursor;
  63.  
  64.   { restores correct cursor for Herc card}
  65.  
  66. Procedure readinteger(Var num : Integer);
  67.  
  68. { readlns an integer from kbd. if enter or invalid entry is entered,
  69.   leaves num unchanged}
  70.  
  71. Procedure readlongint(Var num : LongInt);
  72.  
  73. { readlns a long integer from kbd. if enter or invalid entry is entered,
  74.   leaves num unchanged}
  75.  
  76. Procedure readreal(Var num : Real);
  77.  
  78. { readlns a real from kbd. if enter or invalid entry is entered,
  79.   leaves num unchanged}
  80.  
  81. Procedure greadstring(Var s : String; fieldwidth : Integer);
  82.  
  83.   { readlns a string from kbd in graphics mode}
  84.  
  85. Procedure greadinteger(Var num : Integer);
  86.  
  87. { readlns an integer from kbd in graphics mode. if enter or invalid entry is
  88.   entered, leaves num unchanged}
  89.  
  90. Procedure greadlongint(Var num : LongInt);
  91.  
  92. { readlns a long integer from kbd in graphics mode. if enter or invalid entry
  93.   is entered, leaves num unchanged}
  94.  
  95. Procedure greadreal(Var num : Real);
  96.  
  97. { readlns a real from kbd in graphics mode. if enter or invalid entry is
  98.   entered, leaves num unchanged}
  99.  
  100. Procedure swapscreen;
  101.  
  102.   { change virtual graphics pages, saving current page to heap}
  103.  
  104. Procedure leavegraph;
  105.  
  106.   { return to text mode, but save screen on heap}
  107.  
  108. Procedure entergraph(graphmode : Integer);
  109.  
  110.   { return to graphics mode, restoring saved screen from heap}
  111.  
  112. Procedure screendump;
  113.  
  114.   { graphics hardware independant graphics screen dump}
  115.  
  116. Procedure add_dialogentry(Var dp, lastdialogentry,
  117.                           dialogentryhead : dialogentryp);
  118.  
  119.   { appends dialog entry to list}
  120.  
  121. Procedure dialog_box(dialog : dialogentryp; bcolor, color : Integer;
  122.                      continueprompt : Boolean);
  123.  
  124. { draws arguments messages in dialog box, allows editing of fields,
  125.   restores area under box}
  126.  
  127. Procedure dispose_dialog(Var dp : dialogentryp);
  128.  
  129.   { disposes of all entries in dialog list}
  130.  
  131. Procedure beep;
  132.  
  133.   { short beep on console }
  134.  
  135. Procedure selectcolor(color : Word);
  136.  
  137.   { calls setcolor with modified color value depending on available colors}
  138.  
  139. Procedure selectbcolor(color : Word);
  140.  
  141. Procedure selectfillstyle(pattern : Word; color : Word);
  142.  
  143. { calls selectfillstyle with modified color value depending on available
  144.   colors}
  145.  
  146. Procedure selectbfillstyle(pattern : Word; color : Word);
  147.  
  148. { calls selectfillstyle with modified background color value depending on
  149.   available colors}
  150.  
  151. Procedure fill_background(color, fillpattern, arcsize : Word);
  152.  
  153.   { fills background with color and rounds the corners}
  154.  
  155. Procedure panel(x, y : Integer; width, height, color : Word);
  156.  
  157.   { draws solid panel with center top at x,y, width by height}
  158.  
  159. Procedure add_clickboxentry(Var cp, lastclickbox, clickboxhead : clickboxtypep);
  160.  
  161.   { appends clickbox to list}
  162.  
  163. Procedure draw_clicklist(cp : clickboxtypep; x, y, bcolor, color : Integer);
  164.  
  165.   { draws list of click boxes at given offset}
  166.  
  167. Function click_selection(cp : clickboxtypep; x, y : Integer) : Integer;
  168.  
  169.   { tests whether mouse is over a click box and returns its number in the list}
  170.  
  171. Procedure dispose_clickboxlist(Var cp : clickboxtypep);
  172.  
  173.   { disposes of all entries in click box list}
  174.  
  175. Function continue_prompt(x, y, bcolor, color : Integer) : Char;
  176.  
  177.   { displays continue prompt and waits for button or key}
  178.  
  179. Procedure display_message(s : String; bcolor, color : Integer;
  180.                           Var storagep : Pointer; show       : Boolean);
  181.  
  182.   { draws message in box at screen center (or restores screen if show=false)}
  183.  
  184.  
  185.  
  186.   {********************************************************************}
  187.  
  188. Implementation
  189.  
  190. Const
  191.   screens        = 2;
  192.   bigemptystring =
  193.   '                                                                                                                       ';
  194.  
  195. Var scrnbufp   : Array[1..screens] Of Pointer;
  196.                                   {points to graphics screen save areas}
  197.   currentscreen  : Byte;          {virtual graphics screen currently active}
  198.   firstget       : Array[1..screens] Of Boolean;
  199.                                   {indicate first time screen is saved}
  200.   firstput       : Array[1..screens] Of Boolean;
  201.                                   {indicate first time screen is restored}
  202.   i              : Integer;
  203.  
  204.  
  205.  
  206.   Function log(a : Real)      : Real;
  207.  
  208.     { calculates log base 10 of a}
  209.  
  210.   Begin
  211.     log := 0.434294481*ln(a);
  212.   End;
  213.  
  214.  
  215.   Procedure fixcursor;
  216.  
  217.   Begin
  218.     MemW[0:$460] := $0b0c;
  219.   End;                            {fixcursor}
  220.  
  221.  
  222.   {$f+}
  223.   Procedure myexit; {$f-}
  224.  
  225.     { incase graphics mode, restore text screen before error message is given}
  226.  
  227.   Begin
  228.     restorecrtmode;
  229.     ExitProc := exitsave;
  230.     If showerrormessage Then
  231.       WriteLn('Exit due to internal error!');
  232.   End;                            {myexit}
  233.  
  234.  
  235.   {$f+} Function heapfunc(size : Word)   : Integer; {$f-}
  236.  
  237.     { called when heap error occurs}
  238.  
  239.   Begin
  240.     heapfunc := 1;
  241.     restorecrtmode;
  242.     WriteLn;
  243.     WriteLn;
  244.     WriteLn('Insufficient memory - sorry.', ^g);
  245.     WriteLn;
  246.     Halt;
  247.   End;                            {heapfunc}
  248.  
  249.  
  250.   Procedure heaperrorinit;
  251.  
  252.     { initialised head error pointer to custom procedure}
  253.  
  254.   Begin
  255.     HeapError := @heapfunc;
  256.   End;                            {heaperrorinit}
  257.  
  258.  
  259.   Procedure readinteger(Var num : Integer);
  260.  
  261. { readlns an integer from kbd. if enter or invalid entry is entered,
  262.   leaves num unchanged}
  263.  
  264.   Var st         : String;
  265.     code           : Integer;
  266.     number         : LongInt;
  267.  
  268.   Begin
  269.     ReadLn(st);
  270.     If st <> '' Then
  271.     Begin
  272.       Val(st, number, code);
  273.       If (code = 0) And (number >= -MaxInt) And (number <= MaxInt) Then
  274.         num := number;
  275.     End;
  276.   End;                            {readinteger}
  277.  
  278.  
  279.   Procedure readlongint(Var num : LongInt);
  280.  
  281. { readlns a long integer from kbd. if enter or invalid entry is entered,
  282.   leaves num unchanged}
  283.  
  284.   Var st         : String;
  285.     code           : Integer;
  286.     number         : LongInt;
  287.  
  288.   Begin
  289.     ReadLn(st);
  290.     If st <> '' Then
  291.     Begin
  292.       Val(st, number, code);
  293.       If code = 0 Then
  294.         num := numb